<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="基础信息" name="base">
      <el-card style="margin: 20px;">
        <el-row>
          <el-col :span="12" :offset="6">
            <BaseCreate ref="BaseCreate" :tableId="tableId" resetText="重置" submitText="提交" @onSubmit="handleBaseInfoSubmit"></BaseCreate>
          </el-col>
        </el-row>
      </el-card>
      </el-tab-pane>
      <el-tab-pane label="字段信息" name="props">
        <PropList ref="PropList" :tableId="tableId"></PropList>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { update } from '@/api/workflow/form/table'
import BaseCreate from './components/BaseCreate'
import PropList from './components/PropList'

export default {
  components: { BaseCreate, PropList },
  data() {
    return {
      activeName: 'base',
      tableId: ''
    }
  },
  created() {
    this.tableId = this.$route.query.id
  },
  methods: {
    handleClick(tab, event) {
      if (tab.name === 'base') {
        this.$refs.BaseCreate.fetchData()
      } else if (tab.name === 'props') {
        this.$refs.PropList.fetchData()
      }
    },
    handleBaseInfoSubmit(data) {
      update(data).then(res => {
        this.$message.success('修改成功')
        this.$refs.BaseCreate.btnLoading = false
      }).catch(res => {
        this.$refs.BaseCreate.btnLoading = false
      })
    }
  }
}
</script>
